{% extends 'base.html' %}
{% load widget_tweaks %}

{% block html_title %}
    Review
{% endblock %}


{% block html_body_nav_ol %}

    <li class="breadcrumb-item"><a href="{% url 'home' %}">Home</a></li>
    <li class="breadcrumb-item"><a href="{% url 'review:index' %}">Review</a></li>
    <li class="breadcrumb-item active" aria-current="page">Create</li>

{% endblock %}


{% block html_body %}
    <form enctype="multipart/form-data" method="post">{% csrf_token %}
        {% if formset %}
            {{ formset.management_form }}
            {% for form in formset %}
                {{ form.id }}


                {% if form.non_field_errors %}
                    <div class="alert alert-warning alert-dismissible fade show mt-2" role="alert">
                        <ul>
                            {% for error in form.non_field_errors %}
                                <li>{{ error|escape }}</li>
                            {% endfor %}
                        </ul>
                    </div>
                {% endif %}


                <div class="mb-3">
                    <label for="{{ form.review_profile.id_for_label }}"
                           class="font-weight-bold text-secondary">Review-{{ forloop.counter }} profile:</label>
                    {% render_field form.review_profile class+='form-control' %}
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
                    </div>
                    <div class="custom-file">
                        {% render_field form.final_patch class='custom-file-input' aria-describedby="inputGroupFileAddon01" %}
                        {#    <input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">#}
                        <label class="custom-file-label" for="{{ form.final_patch.id_for_label }}">Choose file</label>
                    </div>

                    <script>
                        $('#{{ form.final_patch.id_for_label }}').on('change', function () {
                            //get the file name
                            var fileName = $(this).val();
                            //replace the "Choose a file" label
                            $(this).next('.custom-file-label').html(fileName);
                        })
                    </script>
                </div>

                {% render_field form.user %}
            {% endfor %}
        {% endif %}

        <div class="row justify-content-end">
            <div class="col-3">
                <input class="mt-3 btn btn-info w-75" type="submit" value="Continue">
            </div>
        </div>
    </form>
    {% if profile_list %}
        {% for profile in profile_list %}
            <p>{{ profile.review_target_people }}</p>
            <p>{{ profile.review_target_groups }}</p>
            <p>{{ profile.review_testing_done }}</p>
            <p>{{ profile.review_repository }}</p>
            <p>{{ profile.review_branch }}</p>
            <p>{{ profile.review_description_template }}</p>
        {% endfor %}
    {% endif %}
{% endblock %}
